/**
 * @author  : ZhiBing.Li
 * @date    : 2013-10-17下午02:25:10
 */
package flexcomm.controls.utils
{
	public class Utils
	{
		/*
		 *	param1: datasource
			param2:	start
			param3:	end
		*/
		public static function Partition(data:Array,left:int,right:int):int
		{
			var tmp:int;
			
			var pivot:int = data[left];
			
			while(left < right)
			{
				while(left < right && data[right] >= pivot)
					right--;
				
				tmp = data[right];
				data[right] = data[left];
				data[left] = tmp;
				
				while(left < right && data[left] <= pivot)
					left++;
				
				tmp = data[right];
				data[right] = data[left];
				data[left] = tmp;
			}
			
			data[left] = pivot;
			return left;
		}
		
		public static function quickSort(data:Array,left:int,right:int):void
		{
			if(left >= right - 1)
				return;
			
			var pivot:int = Partition(data,left,right);
			
			quickSort(data,left,pivot - 1);
			quickSort(data,pivot + 1,right);
		}
	}
}